package com.neotech.neo4j;

import org.apache.log4j.Logger;

import com.neotech.neo4j.resources.ItemType;
import com.neotech.neo4j.rest.Neo4jREST;

/**
 * @author Slobodan
 * @version Neo4j 1.4
 * 
 */
public abstract class Neo4j implements Neo4jDatabase, Neo4jIndex{

	private static Logger log = Logger.getLogger(Neo4j.class.getName());
	
	protected String SERVER_URI;
	protected String NODE_ENTRY_POINT;
	protected String RELATIONSHIP_ENTRY_POINT;
	protected String INDEX_ENTRY_POINT;
	protected boolean logResponse;
	
	public Neo4j(){
	}
	
	public Neo4j(String location){
		this(location, 7474, "/db/data/");
	}	
	
	public Neo4j(String host, int port){
		this(host, port, "/db/data/");
	}
	
	
	public Neo4j(String host, int port, String dataEndpoint){
		SERVER_URI = "http://"+host+":"+port+dataEndpoint;
		NODE_ENTRY_POINT = SERVER_URI + "node/";
		RELATIONSHIP_ENTRY_POINT = SERVER_URI + "relationship/";
		INDEX_ENTRY_POINT = SERVER_URI + "index/";
		log.debug(":: Server url @ "+SERVER_URI+" ::");
	}

	protected String getUrl(Long id, ItemType type) {
		if(type == ItemType.NODE)
			return getNodeUrl(id);
		return getRelationshipUrl(id);
	}
	
	protected String getNodeUrl(Long id){
		return NODE_ENTRY_POINT+id;
	}
	
	protected String getRelationshipUrl(Long id){
		return RELATIONSHIP_ENTRY_POINT+id;
	}

	public boolean isLogResponse() {
		return logResponse;
	}

	public void setLogResponse(boolean logResponse) {
		this.logResponse = logResponse;
	}
	
	
}
